/* Tables of covariate treatment effects for phases I-VII
Except V since the framework doesn't apply to within-person analysis
Use the procedure from Bugni et al.'s car_stata package
Make 11 strata based on the DGPs for which players saw 0 discont
Run regressions by discontinuity level. Collapse to the player level and use average response as DV
*/

clear
set more off

cd "${main}"

cap log close
log using "${logs}/tables_teffects_car.log", replace								

cap file close t1
capture erase "${output}/phase1TE_car.tex"
	file open t1 using "${output}/phase1TE_car.tex", write replace

		file write t1 ///
		"\resizebox*{4.0in}{!}{%"_n ///
		"\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l c c c c c c} "_n ///
		"\vspace{-.45cm} "_n ///
		"&\multicolumn{6}{c}{Dependent variable: player reports discontinuity} \\ "_n ///
		"\cline{2-7} \\" _n ///
		"&\multicolumn{6}{c}{True discontinuity magnitude = } \\ "_n ///
		"\vspace{-.45cm} "_n ///
		" &\multicolumn{6}{c}{} \\"_n ///
		" &    0 &  0.1944 $\sigma$  & 0.324 $\sigma$ & 0.54 $\sigma$ & 0.9 $\sigma$ &  1.5 $\sigma$   \\"_n ///
		"\cline{2-7} \\" _n ///

*----
use "${dat}/Pilot 1.0/survey_merged.dta", clear
cap drop _merge
destring playercorrect, replace

 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)

tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1

foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "B"
replace playertreatment_group_num = 3 if playertreatment_group == "C"
replace playertreatment_group_num = 4 if playertreatment_group == "D"

keep if disc == `d'

sum y if playertreatment_group_num == 0
local treat1_beta_`d' =  string(r(mean), "%10.3fc")
local treat1_se_`d' =  string(.)

collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)

matrix b = e(b)
matrix V_hc = e(V_hc)

forvalues t = 2/4 {
local treat`t'_beta_`d' = string(b[1, `t' - 1], "%10.3fc")
local treat`t'_se_`d' = string(sqrt(V_hc[`t' - 1, `t' - 1]), "%10.3fc")
}
local num_`d' = string(2*e(N), "%10.0fc")
if `d' == 15 {
	local num_`d' = string(e(N), "%10.0fc")
}
list
restore
}

gen treatlab1 = ""
gen treatlab2 = ""
gen treatlab3 = ""
gen treatlab4 = ""

label variable treatlab1 "Small bins; Default y-axis (Mean)"
label variable treatlab2 "Large bins; Default y-axis"
label variable treatlab3 "Small bins; Large y-axis"
label variable treatlab4 "Large bins; Large y-axis"


foreach i in 2 3 4 1 {
if `i' > 1 {
	file write t1 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
	file write t1 "  & (`treat`i'_se_0') & (`treat`i'_se_1944') & (`treat`i'_se_324') & (`treat`i'_se_54') & (`treat`i'_se_9') & (`treat`i'_se_15') \\"_n
	}
if `i' == 1{
	file write t1 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
}	
}

file write t1 "Number of graphs  & `num_0' & `num_1944' & `num_324' & `num_54' & `num_9' & `num_15' \\"_n

gen count = 1
collapse (sum) count, by(pid disc)
gen count2 = 1
collapse (sum) count2, by(disc)

foreach d in 0 9 15 54 324 1944{
su count2 if disc == `d'
local player`d' = r(mean)
}

file write t1 "Number of players  & `player0' & `player1944' & `player324' & `player54' & `player9' & `player15' \\"_n



file write t1 ///
	"\cline{1-7} \\" _n ///
	"\end{tabular*} "_n ///
	"}"_n

file close t1

* Change the reference group to be t2 so we can compare more easily with t4
use "${dat}/Pilot 1.0/survey_merged.dta", clear
cap drop _merge
destring playercorrect, replace

 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)

tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1

keep if playertreatment_group == "B" | playertreatment_group == "D"

foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "D"

keep if disc == `d'
collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)
restore
}

/*==============================================================================
Phase II Table
-----------------------------------*/

cap file close t2
capture erase "${output}/phaseIITE_car.tex"
	file open t2 using "${output}/phaseIITE_car.tex", write replace

		file write t2 ///
		"\resizebox*{4.0in}{!}{%"_n ///
		"\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l c c c c c c} "_n ///
		"\vspace{-.45cm} "_n ///
		"&\multicolumn{6}{c}{Dependent variable: player reports discontinuity} \\ "_n ///
		"\cline{2-7} \\" _n ///
		"&\multicolumn{6}{c}{True discontinuity magnitude = } \\ "_n ///
		"\vspace{-.45cm} "_n ///
		" &\multicolumn{6}{c}{} \\"_n ///
		" &    0 &  0.1944 $\sigma$  & 0.324 $\sigma$ & 0.54 $\sigma$ & 0.9 $\sigma$ &  1.5 $\sigma$   \\"_n ///
		"\cline{2-7} \\" _n ///


*----
use "${dat}/Phase II/survey_merged_PhaseII.dta", clear
destring playercorrect, replace


 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)
tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1




foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "B"
replace playertreatment_group_num = 3 if playertreatment_group == "C"
replace playertreatment_group_num = 4 if playertreatment_group == "D"

keep if disc == `d'

sum y if playertreatment_group_num == 0
local treat1_beta_`d' =  string(r(mean), "%10.3fc")
local treat1_se_`d' =  string(.)

collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)


matrix b = e(b)
matrix V_hc = e(V_hc)

forvalues t = 2/4 {
local treat`t'_beta_`d' = string(b[1, `t' - 1], "%10.3fc")
local treat`t'_se_`d' = string(sqrt(V_hc[`t' - 1, `t' - 1]), "%10.3fc")
}
local num_`d' = string(2*e(N), "%10.0fc")
if `d' == 15 {
	local num_`d' = string(e(N), "%10.0fc")
}

restore
}

gen treatlab1 = ""
gen treatlab2 = ""
gen treatlab3 = ""
gen treatlab4 = ""

label variable treatlab1 "Small bins; Equal spacing (Mean)"
label variable treatlab2 "Large bins; Equal spacing"
label variable treatlab3 "Small bins; Quantile spacing"
label variable treatlab4 "Large bins; Qunatile spacing"


foreach i in 2 3 4 1 {
if `i' > 1 {
	file write t2 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
	file write t2 "  & (`treat`i'_se_0') & (`treat`i'_se_1944') & (`treat`i'_se_324') & (`treat`i'_se_54') & (`treat`i'_se_9') & (`treat`i'_se_15') \\"_n
}
if `i' == 1 {
	file write t2 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
}
}

file write t2 "Number of graphs  & `num_0' & `num_1944' & `num_324' & `num_54' & `num_9' & `num_15' \\"_n

gen count = 1
collapse (sum) count, by(pid disc)
gen count2 = 1
collapse (sum) count2, by(disc)

foreach d in 0 9 15 54 324 1944{
su count2 if disc == `d'
local player`d' = r(mean)
}

file write t2 "Number of players  & `player0' & `player1944' & `player324' & `player54' & `player9' & `player15' \\"_n



file write t2 ///
	"\cline{1-7} \\" _n ///
	"\end{tabular*} "_n ///
	"}"_n

file close t2

/*==============================================================================
Phase III
-------------------------------*/
cap file close t3

capture erase "${output}/phaseIIITE_car.tex"
	file open t3 using "${output}/phaseIIITE_car.tex", write replace

		file write t3 ///
		"\resizebox*{4.0in}{!}{%"_n ///
		"\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l c c c c c c} "_n ///
		"\vspace{-.45cm} "_n ///
		"&\multicolumn{6}{c}{Dependent variable: player reports discontinuity} \\ "_n ///
		"\cline{2-7} \\" _n ///
		"&\multicolumn{6}{c}{True discontinuity magnitude = } \\ "_n ///
		"\vspace{-.45cm} "_n ///
		" &\multicolumn{6}{c}{} \\"_n ///
		" &    0 &  0.1944 $\sigma$  & 0.324 $\sigma$ & 0.54 $\sigma$ & 0.9 $\sigma$ &  1.5 $\sigma$   \\"_n ///
		"\cline{2-7} \\" _n ///

*----
use "${dat}/Phase III/survey_merged_PhaseIII.dta", clear
destring playercorrect, replace


 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)
tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1

foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "B"
replace playertreatment_group_num = 3 if playertreatment_group == "C"

keep if disc == `d'

sum y if playertreatment_group_num == 0
local treat1_beta_`d' =  string(r(mean), "%10.3fc")
local treat1_se_`d' =  string(.)

collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)

matrix b = e(b)
matrix V_hc = e(V_hc)

forvalues t = 2/3 {
local treat`t'_beta_`d' = string(b[1, `t' - 1], "%10.3fc")
local treat`t'_se_`d' = string(sqrt(V_hc[`t' - 1, `t' - 1]), "%10.3fc")
}
local num_`d' = string(2*e(N), "%10.0fc")
if `d' == 15 {
	local num_`d' = string(e(N), "%10.0fc")
}

restore
}

gen treatlab1 = ""
gen treatlab2 = ""
gen treatlab3 = ""

label variable treatlab1 "No fit lines; Vertical line (Mean)"
label variable treatlab2 "Fit lines; Vertical line"
label variable treatlab3 "No fit lines; No vertical line"


foreach i in 2 3 1 {
if `i' > 1 {
	file write t3 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
	file write t3 "  & (`treat`i'_se_0') & (`treat`i'_se_1944') & (`treat`i'_se_324') & (`treat`i'_se_54') & (`treat`i'_se_9') & (`treat`i'_se_15') \\"_n
}
if `i' == 1 {
	file write t3 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
}
}

file write t3 "Number of graphs  & `num_0' & `num_1944' & `num_324' & `num_54' & `num_9' & `num_15' \\"_n

gen count = 1
collapse (sum) count, by(pid disc)
gen count2 = 1
collapse (sum) count2, by(disc)

foreach d in 0 9 15 54 324 1944{
su count2 if disc == `d'
local player`d' = r(mean)
}

file write t3 "Number of players  & `player0' & `player1944' & `player324' & `player54' & `player9' & `player15' \\"_n


file write t3 ///
	"\cline{1-7} \\" _n ///
	"\end{tabular*} "_n ///
	"}"_n

file close t3


/*==============================================================================
Phase VI Table
-----------------------------------*/

cap file close t6
capture erase "${output}/phaseVITE_car.tex"
	file open t6 using "${output}/phaseVITE_car.tex", write replace

		file write t6 ///
		"\resizebox*{4.0in}{!}{%"_n ///
		"\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l c c c c c c} "_n ///
		"\vspace{-.45cm} "_n ///
		"&\multicolumn{6}{c}{Dependent variable: player reports discontinuity} \\ "_n ///
		"\cline{2-7} \\" _n ///
		"&\multicolumn{6}{c}{True discontinuity magnitude = } \\ "_n ///
		"\vspace{-.45cm} "_n ///
		" &\multicolumn{6}{c}{} \\"_n ///
		" &    0 &  0.1944 $\sigma$  & 0.324 $\sigma$ & 0.54 $\sigma$ & 0.9 $\sigma$ &  1.5 $\sigma$   \\"_n ///
		"\cline{2-7} \\" _n ///


*----
use "${dat}/Phase VI/survey_merged_PhaseVI.dta", clear
destring playercorrect, replace


 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)
tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1

foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "B"
replace playertreatment_group_num = 3 if playertreatment_group == "C"
replace playertreatment_group_num = 4 if playertreatment_group == "D"

keep if disc == `d'

sum y if playertreatment_group_num == 0
local treat1_beta_`d' =  string(r(mean), "%10.3fc")
local treat1_se_`d' =  string(.)

collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)

matrix b = e(b)
matrix V_hc = e(V_hc)

forvalues t = 2/4 {
local treat`t'_beta_`d' = string(b[1, `t' - 1], "%10.3fc")
local treat`t'_se_`d' = string(sqrt(V_hc[`t' - 1, `t' - 1]), "%10.3fc")
}
local num_`d' = string(2*e(N), "%10.0fc")
if `d' == 15 {
	local num_`d' = string(e(N), "%10.0fc")
}
restore
}

gen treatlab1 = ""
gen treatlab2 = ""
gen treatlab3 = ""
gen treatlab4 = ""

label variable treatlab1 "Small bins; No fit lines (Mean)"
label variable treatlab2 "Large bins; No fit lines"
label variable treatlab3 "Small bins; Fit lines"
label variable treatlab4 "Large bins; Fit lines"


foreach i in 2 3 4 1 {
if `i' > 1 {
	file write t6 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
	file write t6 "  & (`treat`i'_se_0') & (`treat`i'_se_1944') & (`treat`i'_se_324') & (`treat`i'_se_54') & (`treat`i'_se_9') & (`treat`i'_se_15') \\"_n
}
if `i' == 1 {
	file write t6 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
}
}

file write t6 "Number of graphs  & `num_0' & `num_1944' & `num_324' & `num_54' & `num_9' & `num_15' \\"_n

gen count = 1
collapse (sum) count, by(pid disc)
gen count2 = 1
collapse (sum) count2, by(disc)

foreach d in 0 9 15 54 324 1944{
su count2 if disc == `d'
local player`d' = r(mean)
}

file write t6 "Number of players  & `player0' & `player1944' & `player324' & `player54' & `player9' & `player15' \\"_n

file write t6 ///
	"\cline{1-7} \\" _n ///
	"\end{tabular*} "_n ///
	"}"_n

file close t6

/*==============================================================================
Phase VII Table
-----------------------------------*/

cap file close t7
capture erase "${output}/phaseVIITE_car.tex"
	file open t7 using "${output}/phaseVIITE_car.tex", write replace

		file write t7 ///
		"\resizebox*{4.0in}{!}{%"_n ///
		"\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l c c c c c c} "_n ///
		"\vspace{-.45cm} "_n ///
		"&\multicolumn{6}{c}{Dependent variable: player reports discontinuity} \\ "_n ///
		"\cline{2-7} \\" _n ///
		"&\multicolumn{6}{c}{True discontinuity magnitude = } \\ "_n ///
		"\vspace{-.45cm} "_n ///
		" &\multicolumn{6}{c}{} \\"_n ///
		" &    0 &  0.1944 $\sigma$  & 0.324 $\sigma$ & 0.54 $\sigma$ & 0.9 $\sigma$ &  1.5 $\sigma$   \\"_n ///
		"\cline{2-7} \\" _n ///


*----
use "${dat}/Phase VII/survey_merged_PhaseVII.dta", clear
destring playercorrect, replace


 
destring playerdisc, replace
replace playerdisc = abs(playerdisc)
tab playerdisc, gen(dd)
tab playerdgp, gen(dgpdum)

*dd1 dd2 dd3 dd4 dd5 dd6
gen disc = 0 if dd1 == 1
replace disc = 1944 if dd2 == 1
replace disc = 324 if dd3 == 1
replace disc = 54 if dd4 == 1
replace disc = 9 if dd5 == 1
replace disc = 15 if dd6 == 1

foreach d in 0 9 15 54 324 1944{
preserve

sort pid playerdgp
gen zero_discont = playerdisc == 0
by pid: gen pid_graph_n = _n
gen pid_zeros = zero_discont * pid_graph_n
by pid (playerdgp): gen pid_zero_index = sum(pid_zeros)
egen pid_strata = max(pid_zero_index), by(pid)

gen playertreatment_group_num = 0 // Interpreted as control group
replace playertreatment_group_num = 2 if playertreatment_group == "B"
replace playertreatment_group_num = 3 if playertreatment_group == "C"
replace playertreatment_group_num = 4 if playertreatment_group == "D"

keep if disc == `d'

sum y if playertreatment_group_num == 0
local treat1_beta_`d' =  string(r(mean), "%10.3fc")
local treat1_se_`d' =  string(.)

collapse (mean) y (first) playertreatment_group_num pid_strata, by(pid)
car_sfe y playertreatment_group_num, strata(pid_strata)

matrix b = e(b)
matrix V_hc = e(V_hc)

forvalues t = 2/4 {
local treat`t'_beta_`d' = string(b[1, `t' - 1], "%10.3fc")
local treat`t'_se_`d' = string(sqrt(V_hc[`t' - 1, `t' - 1]), "%10.3fc")
}
local num_`d' = string(2*e(N), "%10.0fc")
if `d' == 15 {
	local num_`d' = string(e(N), "%10.0fc")
}
restore
}

gen treatlab1 = ""
gen treatlab2 = ""
gen treatlab3 = ""
gen treatlab4 = ""

label variable treatlab1 "Homoskedastic global quintic (Mean)"
label variable treatlab2 "Homoskedastic local linear"
label variable treatlab3 "Heteroskedastic global quintic"
label variable treatlab4 "Heteroskedastic local linear"


foreach i in 2 3 4 1 {
if `i' > 1 {
	file write t7 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
	file write t7 "  & (`treat`i'_se_0') & (`treat`i'_se_1944') & (`treat`i'_se_324') & (`treat`i'_se_54') & (`treat`i'_se_9') & (`treat`i'_se_15') \\"_n
}
if `i' == 1 {
	file write t7 "`: variable label treatlab`i''   & `treat`i'_beta_0' & `treat`i'_beta_1944' & `treat`i'_beta_324' & `treat`i'_beta_54' & `treat`i'_beta_9' & `treat`i'_beta_15' \\"_n
}
}

file write t7 "Number of graphs  & `num_0' & `num_1944' & `num_324' & `num_54' & `num_9' & `num_15' \\"_n

gen count = 1
collapse (sum) count, by(pid disc)
gen count2 = 1
collapse (sum) count2, by(disc)

foreach d in 0 9 15 54 324 1944{
su count2 if disc == `d'
local player`d' = r(mean)
}

file write t7 "Number of players  & `player0' & `player1944' & `player324' & `player54' & `player9' & `player15' \\"_n

file write t7 ///
	"\cline{1-7} \\" _n ///
	"\end{tabular*} "_n ///
	"}"_n

file close t7


log close
